#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "fuzzy.h"

void category::setname(char *n)
{
    strcpy(name, n);
}

char * category::getname()
{
    return name;
}

void category::setval(float &h, float &m, float &l)
{
    highval = h;
    midval = m;
    lowval = l;
}

float category::getlowval()
{
    return lowval;
}

float category::getmidval()
{
    return midval;
}

float category::gethighval()
{
    return highval;
}

float category::getshare(const float & input)
{
    float output;
    float midlow, highmid;
    midlow = midval - lowval;
    highmid = highval - midval;
    if ((input <= lowval) || (input >= highval))
        output = 0;
    else
    {
        if (input > midval)
            output = (highval - input) / highmid;
        else
            if (input == midval)
                output = 1.0;
            else
                output = (input - lowval) / midlow;
    }
    return output;
}

int randomnum(int maxval)
{
    srand ((unsigned) time(NULL));
    return rand() % maxval;
}
